package com.xbao.controller;

import com.aliyuncs.CommonRequest;
import com.xbao.core.component.page.Pagination;
import com.xbao.core.http.CommRequest;
import com.xbao.core.http.CommResult;
import com.xbao.model.req.PeriodRecordReq;
import com.xbao.model.req.PeriodReq;
import com.xbao.model.req.PeriodRuleReq;
import com.xbao.model.vo.PeriodRecordVo;
import com.xbao.model.vo.PeriodRuleVo;
import com.xbao.service.PeriodRecordService;
import com.xbao.service.PeriodRuleService;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by qingshengzheng on 18/8/25.
 */
@RequestMapping(value = "period")
@Controller
@EnableAutoConfiguration
public class PeriodController extends BaseController {
    @Resource
    private PeriodRuleService periodRuleService;
    @Resource
    private PeriodRecordService periodRecordService;

    @RequestMapping(value = "modifyrecord")
    @ResponseBody
    public CommResult modifyPeriodRecord(CommRequest<PeriodRecordReq>  reqCommRequest){
        periodRecordService.modifyPeriodRecord(reqCommRequest.getData());
        return result();
    }
    @RequestMapping(value = "recordsOfcls")
    @ResponseBody
    public CommResult<List<PeriodRecordVo>> periodsRecordsOfCls(CommRequest<PeriodRecordReq> reqCommRequest) {
        List<PeriodRecordVo> vos = periodRecordService.queryPeriodRecordOfCls(reqCommRequest.getData().getCid());
        return new CommResult<List<PeriodRecordVo>>(vos);
    }
    @RequestMapping(value = "deleteRecords")
    @ResponseBody
    public CommResult deletePeriodRecords(CommRequest<List<PeriodRecordReq>> reqCommRequest){
        periodRecordService.deletePeriodRecords(reqCommRequest.getData());
        return result();
    }

    @RequestMapping(value = "addrule")
    @ResponseBody
    public CommResult addPeriodRule(CommRequest<PeriodRuleReq> periodReqCommRequest) {
        periodRuleService.addPeriodRule(periodReqCommRequest.getData());
        return result();
    }
    @RequestMapping(value = "queryrule")
    @ResponseBody
    public CommResult<List<PeriodRuleVo>> queryPeriodRule(CommRequest<PeriodRuleReq> periodReqCommRequest) {
        List<PeriodRuleVo> vos = periodRuleService.queryPeriods(periodReqCommRequest.getData());
        return new CommResult<List<PeriodRuleVo>>(vos);
    }
    @RequestMapping(value = "updaterule")
    @ResponseBody
    public CommResult updatePeriodRule(CommRequest<PeriodRuleReq> periodReqCommRequest) {
        periodRuleService.modifyPeriodRule(periodReqCommRequest.getData());
        return result();

    }
    @RequestMapping(value = "detailrule")
    @ResponseBody
    public CommResult detailPeriodRule(CommRequest<PeriodRuleReq> periodReqCommRequest) {
        periodRuleService.deletePeriodRule(periodReqCommRequest.getData().getId());
        return result();
    }
}
